using UnityEngine;
using UnityEngine.UI;

public class DrinkCounter : MonoBehaviour
{
	private Text textComponent;

	private int maxDrinks;

	private int currentDrinks;

	private bool drinkCounterHidden;

	private float translationOffsetX = 4f;

	private float animationShowTime = 0.6f;

	private float animationHideTime = 0.6f;

	private void Awake()
	{
		textComponent = GetComponentInChildren<Text>();
	}

	public void SetMaxDrinks(int maxDrinks)
	{
		this.maxDrinks = maxDrinks;
		if (maxDrinks < 0)
		{
			maxDrinks = 0;
		}
		UpdateText();
	}

	public void SetCurrentDrinks(int currentDrinks)
	{
		this.currentDrinks = currentDrinks;
		if (currentDrinks >= maxDrinks)
		{
			currentDrinks = maxDrinks;
		}
		if (currentDrinks < 0)
		{
			currentDrinks = 0;
		}
		UpdateText();
	}

	public void AddNextDrink()
	{
		currentDrinks++;
		if (currentDrinks > maxDrinks)
		{
			currentDrinks = maxDrinks;
		}
		UpdateText();
	}

	public void InitWith(int currentDrinks, int maxDrinks)
	{
		SetMaxDrinks(maxDrinks);
		SetCurrentDrinks(currentDrinks);
		UpdateText();
	}

	private void UpdateText()
	{
		textComponent.text = currentDrinks + "/" + maxDrinks;
	}

	public void ShowDrinkCounter()
	{
		if (drinkCounterHidden)
		{
			drinkCounterHidden = false;
			iTween.MoveBy(base.gameObject, Vector3.right * translationOffsetX, animationShowTime);
		}
	}

	public void HideDrinkCounter(bool hideImmediately)
	{
		if (!drinkCounterHidden)
		{
			drinkCounterHidden = true;
			if (hideImmediately)
			{
				base.transform.Translate(Vector3.left * translationOffsetX);
			}
			else
			{
				iTween.MoveBy(base.gameObject, Vector3.left * translationOffsetX, animationHideTime);
			}
		}
	}

	public int GetCurrentDrink()
	{
		return currentDrinks;
	}

	public int GetMaxDrinks()
	{
		return maxDrinks;
	}
}
